package com.example.demo.commom;

import com.example.demo.entity.Userinfo;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User:龙宝
 * Date:2023-04-02
 * Time:10:41
 */
/*
当前登录用户相关的操作
 */
public class UserSessionUtils {
    /*
    得到当前的登录用户
     */
    public static Userinfo getUser(HttpServletRequest request) {
        HttpSession session = request.getSession(false);
        if(session != null && session.getAttribute(AppVariable.USER_SESSION_KEY)!=null) {
            //用户已经登陆了
            System.out.println((Userinfo) session.getAttribute(AppVariable.USER_SESSION_KEY));
            return (Userinfo) session.getAttribute(AppVariable.USER_SESSION_KEY);
        }
        return null;
    }
}
